unit u_conshstpadrao;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables, ExtCtrls, StdCtrls, Buttons, Grids, DBGrids, ComCtrls;

type
  Tf_conshstpadrao = class(TForm)
    bs: TStatusBar;
    Panel1: TPanel;
    Panel2: TPanel;
    btnFechar: TBitBtn;
    btnBuscar: TBitBtn;
    btnCancelar: TBitBtn;
    Panel4: TPanel;
    Timer1: TTimer;
    ds1: TDataSource;
    dbctbhis: TDatabase;
    dbg: TDBGrid;
    Panel3: TPanel;
    Label1: TLabel;
    edtDesc: TEdit;
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure dbgKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure btnBuscarClick(Sender: TObject);
    procedure edtDescExit(Sender: TObject);
    procedure edtDescKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnCancelarClick(Sender: TObject);
    procedure btnFecharClick(Sender: TObject);
  private
    { Private declarations }
  public
    hemp_codigo, xhst_codigo: string;
    hordem: Integer;
    henter, hok: boolean;
    { Public declarations }
  end;

var
  f_conshstpadrao: Tf_conshstpadrao;

implementation

{$R *.DFM}
var
  tqhis: tquery;

procedure Tf_conshstpadrao.FormActivate(Sender: TObject);
begin
  Bs.Panels.Items[2].Text := datetostr(date);
  Bs.Panels.Items[3].Text := timetostr(time);
  dbctbhis.Connected := True;
  henter := False;
  tqhis := tquery.Create(self);
  tqhis.DatabaseName := dbctbhis.DatabaseName;
  tqhis.active := false;
  ds1.DataSet := tqhis;
  tqhis.params.clear;
  tqhis.sql.clear;
  tqhis.active := False;
  tqhis.sql.add('select * from hstpadrao order by hst_codigo');
  tqhis.open;
end;

procedure Tf_conshstpadrao.FormCreate(Sender: TObject);
begin
  hordem := 0;
end;

procedure Tf_conshstpadrao.dbgKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = VK_F2 then begin
    btnBuscar.OnClick(Sender);
  end else if key = VK_ESCAPE then begin
    btnCancelar.OnClick(Sender);
  end else if key = 12 then begin
    btnfechar.onclick(sender);
  end;
end;

procedure Tf_conshstpadrao.btnBuscarClick(Sender: TObject);
begin
  panel3.Visible := True;
  edtDesc.SetFocus;
end;

procedure Tf_conshstpadrao.edtDescExit(Sender: TObject);
begin
  panel3.visible := False;
end;

procedure Tf_conshstpadrao.edtDescKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = 12 then begin
    tqhis.Locate('hst_descricao', edtdesc.text, [loPartialKey]);
    btnFechar.SetFocus;
  end;
  if key = VK_ESCAPE then begin
    dbg.SetFocus;
  end;
end;

procedure Tf_conshstpadrao.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  dbctbhis.Connected := False;
end;

procedure Tf_conshstpadrao.btnCancelarClick(Sender: TObject);
begin
  hok := False;
  tqhis.Close;
  tqhis.Active := false;
  dbctbhis.Connected := false;
  close;
end;

procedure Tf_conshstpadrao.btnFecharClick(Sender: TObject);
begin
  if tqhis.RecNo <> 0 then begin
    xhst_codigo := dbg.Fields[0].asstring;
  end else begin
    xhst_codigo := '';
  end;
  hok := True;
  tqhis.Close;
  tqhis.Active := false;
  dbctbhis.Connected := false;
  close;
end;

end.
